package greendbgui

class Address 
{
	static mapping = 
	{
		version false
	}
	
	static hasMany = [electoralRollEntry:ElectoralRollEntry]

    static constraints = {
    }

    String address1
    String address2
    String address3
    String address4
    String address5
    String postcode

  	String toString()
	{
    	return address1 + ", " + address2 + ", " + address3 + ", " + address4 + ", " + address5 + ", " + postcode
  	}
	
	String getSingleLine()
	{
	    StringBuffer sb = new StringBuffer (address1 + ", ");
	    
        if (address2.length() > 0)
            sb.append (address2 + ", ");
        
        if (address3.length() > 0)
            sb.append (address3 + ", ");
        
        if (address4.length() > 0)
            sb.append (address4 + ", ");
        
        if (address5.length() > 0)
            sb.append (address5 + ", ");
        
        sb.append (postcode);
        
        return sb.toString();
	}
	
	List<String> getMultiLine()
	{
	    List<String> l = new LinkedList<String>()
	    
	    l.add (address1)
	    
        if (address2.length() > 0)
            l.add (address2);
        
        if (address3.length() > 0)
            l.add (address3);
        
        if (address4.length() > 0)
            l.add (address4);
        
        if (address5.length() > 0)
            l.add (address5);
        
        l.add (postcode);
	    
        return l
	}

    boolean equals(o) 
    {
        if (this.is(o)) return true;
    
        if (!o || getClass() != o.class) return false;
    
        Address that = (Address) o;
    
        if (id? !id.equals(that.id) : that.id!= null) return false;
    
        return true;
    }
	
}
